package com.course.component.exceptions;
/*
@author By 林中小鸟
@package  com.self.introduction.component.exceptions
@create 2021 - 11 - 2021\11\25 0025
@QQ: 357182695
@Em: themooncss@gmail.com
*/

import com.course.component.http.Crp;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.security.auth.login.LoginException;

@RestControllerAdvice
public class ApiExceptionHandler {

    @ExceptionHandler
    public Crp unknownException(Exception e) {
        return new Crp(500,e.getMessage(), false);
    }

    @ExceptionHandler(JwtException.class)
    public Crp jwtException(JwtException e) {
        return new Crp(e.getCode(),e.getMessage(), e.getData());
    }

    @ExceptionHandler(LoginException.class)
    public Crp loginException(LoginException e) {
        return new Crp(500, e.getMessage(), false);
    }

    @ExceptionHandler(FileException.class)
    public Crp fileException(FileException e) {
        return new Crp(500, e.getMessage(), false);
    }
}
